package com.pzl.dashboardview;

import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.Canvas;
import android.os.Parcelable;
import android.util.AttributeSet;
import android.util.Log;
import android.view.MotionEvent;
import android.view.View;

/**
 * Created by zl.peng on 2016-02-02.
 */
public class DashboardView extends View {
    private static final String TAG = "DashboardView";
    private DialPlate mDialPlate;
    private int mSegmentNum;
    private int mMaxValue;
    private int mWidth, mHeight;
    private int mFinalStaticValue;

    public DashboardView(Context context) {
        this(context, null);
    }

    public DashboardView(Context context, AttributeSet attrs) {
        this(context, attrs, 0);
    }

    public DashboardView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);

        if (mDialPlate == null) {
            //给默认
            mDialPlate = new SimpleProgress();
        }

        TypedArray ta = context.obtainStyledAttributes(attrs, R.styleable.DashboardView);
        mMaxValue = ta.getInt(ta.getIndex(R.styleable.DashboardView_MaxValue), 0);
        mSegmentNum = ta.getInt(ta.getIndex(R.styleable.DashboardView_SegmentNum), 0);

        ta.recycle();
    }

    @Override
    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
        super.onMeasure(widthMeasureSpec, heightMeasureSpec);

        mWidth = getMeasuredWidth();
        mHeight = getMeasuredHeight();
    }

    @Override
    protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
        super.onLayout(changed, left, top, right, bottom);
    }

    @Override
    protected void onDraw(Canvas canvas) {

        mDialPlate.onDraw(this, canvas);
    }

    @Override
    public boolean onTouchEvent(MotionEvent event) {
        return super.onTouchEvent(event);
    }

    public void setTemplate(DialPlate dialPlate) {
        mDialPlate = null;
        mDialPlate = dialPlate;
    }

    /**
     * 设置静态数据
     *
     * @param staticValue
     */
    public void setStaticValue(int staticValue) {
        mFinalStaticValue = staticValue;
        mDialPlate.setStaticValue(staticValue);
    }

    /**
     * 更新当前数据
     *
     * @param currentValue
     */
    public void updateCurrentValue(int currentValue) {
        mDialPlate.onUpdate(currentValue);
    }

    public int getmSegmentNum() {
        return mSegmentNum;
    }

    public int getmMaxValue() {
        return mMaxValue;
    }

    public int getmWidth() {
        return mWidth;
    }

    public int getmHeight() {
        return mHeight;
    }


}
